<%@ page contentType="text/html; charset=utf-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="primus" tagdir="/WEB-INF/tags" %>
<%@ taglib prefix="fn" tagdir="/WEB-INF/tags/form" %>
<primus:page title="订单拦截管理">
    <jsp:attribute name="css">
        <style type="text/css">
            #table .operate {
                min-width: 80px;
            }
        </style>
    </jsp:attribute>
    <jsp:attribute name="script">
        <script type="application/javascript">
            $(function () {
                $("#table").DataTable({
                    "lengthMenu": [[10, 20, 50, -1], [10, 20, 50, "所有"]],
                    "columnDefs": [{"targets": [7], "orderable": false}],
                    "searching": false,
                    "order": [[0, "asc"]]
                });
            });
            $("body").on("click", ".geo-line", function () {
                var id = $(this).data("id");
            })
        </script>
    </jsp:attribute>
    <jsp:body>
        <div class="breadcrumbs ace-save-state" id="breadcrumbs">
            <ul class="breadcrumb">
                <li>
                    <i class="ace-icon fa fa-home home-icon"></i>
                    <a href="welcome.do">
                        首页
                    </a>
                </li>
                <li>
                    <a href="geo/provinces">
                        订单管理
                    </a>
                </li>
                <li class="active">
                    订单拦截管理
                </li>
            </ul>
        </div>

        <div class="page-content">

            <div class="row">
                <div class="col-xs-12">
                    <!-- PAGE CONTENT BEGINS -->
                    <div class="row">
                        <div class="col-xs-12">
                            <h3 class="header smaller lighter blue">
                                订单拦截管理
                            </h3>
                            <div class="row">
                                <div class="form-group row">
                                    <div class="col-sm-3">
                                        <button class="btn btn-primary" id="addButton">
                                            新增
                                        </button>
                                    </div>
                                    <label class="col-sm-1 control-label no-padding-right">订单编号</label>
                                    <div class="col-sm-3">
                                        <input type="text" class="col-xs-12 col-sm-12" placeholder="订单编号" id="orderInput">
                                    </div>
                                    <button type="button" class="btn btn-warning ace-icon fa fa-search btn-sm" id="searchButton">
                                        搜索
                                    </button>
                                    <button type="button" class="btn btn-inverse ace-icon fa fa-refresh btn-sm" id="refreshButton">
                                        重置
                                    </button>
                                </div>
                            </div>
                        </div>

                            <div class="row">
                                <table id="table" class="table table-bordered table-striped"
                                       style="width: 100%;">
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <script>
            $(function(){
                // 初始化加载
                first();

                //关闭datatable弹窗提示
                $.fn.dataTable.ext.errMode = 'none'; //不显示任何错误信息

            });

            // 订单编码检验
            $("#orderInput").blur(function(){
                var inpu = $("#orderInput").val();
                if (inpu != "") {
                    if (inpu.length > 65){
                        layer.msg("对不起，订单编码长度不可超过65")
                    }
                }
            });

            // 订单搜索
            $("#searchButton").on("click", function () {
                var sele = $("#orderSele").val();
                var inpu = $("#orderInput").val();
                var dttable = $('#table').dataTable();
                dttable.fnClearTable(); //清空一下table
                dttable.fnDestroy(); //还原初始化了的datatable
                first();
            });

            // 重置按钮
            $("#refreshButton").on("click", function () {
                $("#orderSele").val("WAIT_PAY");
                $("#orderInput").val("");
                $('#table').dataTable().api().ajax.reload(null, false);
            })

            // 表格加载
            function first() {
                $("#table").dataTable({
                    searching: false,
                    ordering: false,
                    bProcessing : true, //开启读取服务器数据时显示正在加载中……特别是大数据量的时候，开启此功能比较好
                    bServerSide : true,//服务器处理分页，默认是false，需要服务器处理，必须true
//                    sAjaxDataProp : "aData",//是服务器分页的标志，必须有
                    bPaginate : true,//分页工具条显示
                    lengthMenu: [10, 20, 50],
                    ajax: {
                        url: '/interception/interceptionList',
                        type: 'GET',
                        dataType: "json",
                    },
                    columns: [
                        {
                            "title": "操作",
                        },{
                            "title": "当前状态",
                            "data": "state"
                        },
                        {
                            "title": "拦截类型",
                            "data": "orderInterceptType"
                        },
                        {
                            "title": "属性名",
                            "data": "propertyName"
                        },
                        {
                            "title": "属性值",
                            "data": "propertyValue"
                        },
                        {
                            "title": "创建时间",
                            "data": "createTimestamp"
                        },
                        {
                            "title": "id",
                            "data": "idStr"
                        },
                    ],
                    columnDefs: [
                        {
                            "targets": [0],
                            "defaultContent": "",
                            "class": "text-center nowrap",
                            "render": function (data, type, row, full, meta) {
                               return operationFormmater(data, type, row, full, meta);
                            }
                        },
                        {
                            "targets": [1],
                            "defaultContent": "",
                            "class": "text-center nowrap",
                            "render": function (data, type, row, full, meta) {
                                if (data != null) {
                                    if (data) {
                                        return "启动";
                                    } else {
                                        return "关闭";
                                    }
                                }
                            }
                        },
                        {
                            "targets": [2],
                            "defaultContent": "",
                            "class": "text-center nowrap",
                            "render": function (data, type, row, full, meta) {
                                if (data != null) {
                                    if (data == "all") {
                                        return "所有订单";
                                    } else if (data == "now") {
                                        return "立即送";
                                    } else if (data == "normal") {
                                        return "普通送";
                                    } else if (data == "appointment") {
                                        return "预约送";
                                    }
                                }
                            }
                        },
                        {
                            "targets": [3],
                            "defaultContent": "",
                            "class": "text-center nowrap",
                            "render": function (data, type, row, full, meta) {
                                if (data != null) {
                                    if (data == "product_code") {
                                        return "商品编码";
                                    } else if (data == "order_amount") {
                                        return "订单总金额";
                                    }
                                }
                            }
                        },
                        {
                            "targets": [4],
                            "defaultContent": "",
                            "class": "text-center nowrap"
                        },
                        {
                            "targets": [5],
                            "defaultContent": "",
                            "class": "text-center nowrap",
                            "render": function (data, type, row) {
                                if (data != undefined) {
                                    return localDateFormmater(data);
                                }
                            }
                        },
                        {
                            "targets": [7],
                            "defaultContent": "",
                            "class": "text-center nowrap",
                            "bSearchable": false
                        },
                    ],
                });
            }

            // 表格添加'详情'按钮
            function operationFormmater(data, type, row, full, meta) {
                return "<button type=\"button\" class=\"btn btn-danger ace-icon btn-sm\" onclick=\"del(" + full.row + ")\">\n" +
                    "                                        删除\n" +
                    "                                    </button>"
                    +
                        "&nbsp;&nbsp;&nbsp;"+
                    "<button type=\"button\" class=\"btn btn-danger ace-icon btn-sm\" onclick=\"edit(" + full.row + ")\">\n" +
                    "                                        变更\n" +
                    "                                    </button>"
                    ;
            }

            // 删除按钮(删除记录)
            function del(row) {
            }

            // 变更按钮(修改数据状态)
            function edit(row) {
            }

            // 新增按钮
            $("#addButton").on("click", function () {
                window.location.href="/interception/interceptionAdd";   //跳转详情页面
            })

            // 时间格式化
            function localDateFormmater(data) {
                var time = " "+data[3]+":"+data[4]+":"+data[5];
                var day = data[0]+"-"+data[1]+"-"+data[2];
                return day+time;
            }
        </script>
    </jsp:body>
</primus:page>